package com.fahai.web.service.impl;/**
 * Created by WangKe on 17/5/22.
 */

import com.fahai.common.IConfType;
import com.fahai.common.PageVo;
import com.fahai.web.dao.MarketDao;
import com.fahai.web.entity.AllConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 全局变量服务类
 *
 * @author
 * @create 2017-05-22 下午5:23
 **/
@Service
@Transactional(rollbackFor = DataAccessException.class)
public class MarketServiceImpl implements com.fahai.web.service.MarketService {
    @Autowired
    private MarketDao allConfigDao;

    @Override
    public void updateAllConfig(AllConfig allConfigVo) {
        AllConfig allConfig = allConfigDao.selectByPrimaryKey(allConfigVo.getAllId());
        allConfig.setConfName(allConfigVo.getConfName());
        allConfig.setRemark(allConfigVo.getRemark());
        allConfig.setConfValue(allConfigVo.getConfValue());
        allConfigDao.updateByPrimaryKeySelective(allConfig);
    }



    /**
     * 保存运营规则信息
     *
     * @param allConfig
     */
    @Override
    public void insertAllConfig(AllConfig allConfig) {
        allConfig.setIsStatus(0);
        allConfig.setConfType(IConfType.getConfType_schd);//TODO 尚未确定
        allConfigDao.insert(allConfig);
    }

    /**
     * 查询全局变量
     *
     * @param allConfig
     * @param pageVo
     * @return
     */
    @Override
    public PageVo findAllConfig(AllConfig allConfig, PageVo pageVo) {
        Map<String, Object> map = new HashMap<String, Object>();
//        Page<UserInfo> page = PageHelper.startPage(pageVo.getPageNum(), pageVo.getPageSize());
        map.put("confName", allConfig.getConfName());
        List<AllConfig> allconfigs = allConfigDao.selectAll3(map);
        pageVo.setResult(allconfigs);
        return pageVo;
    }
}
